package thread;

/**
 * 线程的优先级
 * 线程有10个优先级,分别用整数1-10表示,其中1为最低级,10为最高优先级.
 * 5为默认值,优先级越高的线程获取CPU时间片的次数越多.
 *
 *
 * 线程start后就会纳入到线程调度器程序中统一管理,线程无法主动索取时间片,
 * 是能被动被分配,调整优先级可以最大程度的改善获取时间片的次数
 *
 * void setPriority(int priority)
 */
public class PriorityDemo {
    public static void main(String[] args) {
        Thread man = new Thread(){
            public void run(){
                for (int i = 0; i < 1000; i++) {
                    System.out.println("6");
                }
            }
        };
        Thread min = new Thread(){
            public void run(){
                for (int i = 0; i < 1000; i++) {
                    System.out.println("9");
                }
            }
        };
        Thread norm = new Thread(){
            public void run(){
                for (int i = 0; i < 1000; i++) {
                    System.out.println("0");
                }
            }
        };
        min.setPriority(Thread.MIN_PRIORITY);
        man.setPriority(Thread.MAX_PRIORITY);
        min.start();
        man.start();
        norm.start();
    }
}
